import type { Profile } from '@/types/router'
import { getToken, removeToken, setToken } from '@/utils/auth'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore('hm-user', () => {
  const token = ref(getToken()||'')
  // 存储token
  const setStoreToken=(newToken:string)=>{
    token.value=newToken
     setToken(token.value)
  }
  // 删除token
  const removeStoreToken=()=>{
    token.value=''
    removeToken()
  }
  const profile=ref<Profile>({} as Profile)
  const setProfile=(newProfile:Profile)=>{
    profile.value=newProfile
  }
  const removeProfile=()=>{
    profile.value={} as Profile
  }
  return {
    token,
    setStoreToken,
    removeStoreToken,
    profile,
    setProfile,
    removeProfile
  }
})
